package org.infocorp.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.infocorp.domain.Person;
import org.infocorp.excepcion.DAOExcepcion;
import org.infocorp.util.ConexionBD;

public class InfocorpDAO extends BaseDAO{

	public Person getDeuda(String strNroDni) throws DAOExcepcion {		
		System.out.println("DatosDniDAO: getDatosDniDao(Persona oPersona)");			
		String query = "SELECT SUM(DEUDA) 'Deuda' FROM INFOCORP.DEUDA WHERE NRODNI = ?";		

		Person objInfoDeuda = new Person();
		Connection con = null;
		PreparedStatement stmt = null;
		ResultSet rs = null;
		try {
			con = ConexionBD.getConexion();
			stmt = con.prepareStatement(query);
			stmt.setString(1, strNroDni);			
			rs = stmt.executeQuery();
			if (rs.next()) {				
				objInfoDeuda.setMoney(rs.getDouble("Deuda"));				
			}
		} catch (SQLException e) {
			throw new DAOExcepcion(e.getMessage());
		} finally {
			this.cerrarResultSet(rs);
			this.cerrarStatement(stmt);
			this.cerrarConexion(con);
		}
		return objInfoDeuda;
	}

}
